This is an inconsistent synchronization bug.
The private field "closed" in
org.apache.commons.pool.BaseObjectPool
is neither volatile, nor the accesses to "closed" are synchronized.
More details about this bug are at POOL-46 JIRA page.
...code snippet 2:
2 testBasePool.close();
...
...
while (true) {
1 if (testBasePool.isClosed()) {
break;
}
}
...
This bug is reproduced under pool 1.2 and JDK 1.6.0_33.
Execute the following scripts to run the test to reproduce the bug (assume the location of the pool test project is pool_test_home).
Linux:
${pool_test_home}/scripts/46.sh
Windows:
%pool_test_home%\scripts\46.bat